﻿@page
@using System.Security.Claims;
@model FytSoa.Web.Pages.FytAdmin.IndexModel
@{
    ViewData["Title"] = "管理平台";
    Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<div class="layui-layout layui-layout-admin">
    <div class="layui-header" id="mainapp">
        <div class="layui-logo">FytErp-SaaS平台</div>
        <ul class="layui-nav layui-layout-left layui-first-nav" lay-filter="topmenu">
            <li class="layui-nav-item layui-this" v-for="(it,index) in menulist" v-cloak v-if="it.layer===1 && index===0"><a href="javascript:void(0)" :data-index="index"><i :class="'layui-icon '+it.icon"></i>{{it.name}}</a></li>
            <li class="layui-nav-item" v-for="(it,index) in menulist" v-cloak v-if="it.layer===1 && index!=0"><a href="javascript:void(0)" :data-index="index"><i :class="'layui-icon '+it.icon"></i>{{it.name}}</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a data-pjax href="/fytadmin/default"><i class="layui-icon"></i></a>
            </li>
            <li class="layui-nav-item">
                <a href="/demo/"><i class="layui-icon"></i><span class="layui-badge-dot"></span></a>
            </li>
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <span class="username">@User.Identities.First(u => u.IsAuthenticated).FindFirst(ClaimTypes.Name).Value <i class="layui-icon"></i></span>
                    <img src="@User.Identities.First(u => u.IsAuthenticated).FindFirst(ClaimTypes.Thumbprint).Value" class="layui-nav-img">
                </a>
                <dl class="layui-nav-child">
                    <dd><a data-pjax href="/fytadmin/sys/admin/">个人中心</a></dd>
                    <hr />
                    <dd><a href="/fytadmin/logout/">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black" id="rmapp">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree fyt-nav-tree layui-hide" v-for="(m,mindex) in tmlist">
                <li class="layui-nav-item" v-for="(it,index) in list" v-cloak v-if="it.layer===2 && it.parentGuid===m.guid">
                    <a class="" href="javascript:;"><i :class="'layui-icon '+it.icon"></i>{{it.name}}</a>
                    <dl class="layui-nav-child">
                        <dd v-for="row in list" v-if="row.layer===3 && row.parentGuid===it.guid"><a data-pjax :href="row.urls">{{row.name}}</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body" id="main-container">

    </div>
</div>
<div class="load-container load8">
    <div class="load-wall">
        <div class="loader">Loading...</div>
    </div>
</div>
<script type="text/javascript" src="~/themes/js/echarts.min.js"></script>
<script type="text/javascript" src="~/themes/js/macarons.js"></script>
<script type="text/javascript" src="~/themes/js/nprogress.js"></script>
<script>
    var main_vm = new Vue({
        el: '#mainapp',
        data: {
            menulist: []
        }
    });
    var rm_vm = new Vue({
        el: '#rmapp',
        data: {
            tmlist: [],
            list: []
        }
    });
    layui.config({
        base: '/themes/js/modules/'
    }).use(['element', 'layer', 'jquery', 'common', 'pjax'], function () {
        var os = layui.common
            , element = layui.element
            , $ = layui.jquery;
        os.get('api/menu/authmenu', { parm: '@Model.adminGuid' }, function (res) {
            if (res.statusCode === 200) {
                $.each(res.data, function (index, item) {
                    if (item.layer === 1) {
                        main_vm.menulist.push(item);
                    }
                });
                rm_vm.tmlist = main_vm.menulist;
                rm_vm.list = res.data;
                main_vm.$nextTick(function () {
                    element.render();
                    //定位到菜单
                    $(".layui-bg-black .fyt-nav-tree li a").each(function () {
                        if (window.location.pathname === $(this).attr('href')) {
                            $(".layui-bg-black .fyt-nav-tree li").removeClass('layui-nav-itemed');
                            $(this).parents('.layui-nav-item').addClass('layui-nav-itemed');
                            $(this).parent().addClass('layui-this');
                        }
                    });
                    $(".load8").fadeOut(200);
                    element.on('nav(topmenu)', function (elem) {
                        var that = $(elem);
                        var topIndex = that.data('index');
                        $("#rmapp .layui-side-scroll ul").addClass('layui-hide');
                        $("#rmapp .layui-side-scroll ul").eq(topIndex).removeClass('layui-hide');
                    });
                    $("#rmapp .layui-side-scroll ul").eq(0).removeClass('layui-hide');
                });
            } else {
                os.error(res.message); 
            }
        });
        $.pjax({
            url: '/fytadmin/default',
            container: '#main-container',
            fragment: '#container'
        });
        $('.layui-layout-admin').pjax('a', '#main-container',
            {
                fragment: "#container",
                cache: false,
                show: 'fade'
            }
        );
        $(document).on('pjax:start', function () { NProgress.start(); $(".load8").show(); });
        $(document).on('pjax:end', function () { NProgress.done(); $(".load8").fadeOut(200); });
    });
</script>
